package com.dingreading.cloud.admin.service.impl;

import com.dingreading.cloud.admin.entity.OrderFormImage;
import com.dingreading.cloud.admin.entity.table.OrderFormImageTableDef;
import com.dingreading.cloud.admin.mapper.OrderFormImageMapper;
import com.dingreading.cloud.admin.service.OrderFormImageService;
import com.mybatisflex.core.query.QueryCondition;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2024-02-24
 */
@Service
public class OrderFormImageServiceImpl extends BaseServiceImpl<OrderFormImageMapper, OrderFormImage, OrderFormImageTableDef> implements OrderFormImageService {

    @Override
    protected OrderFormImageTableDef getTable() {
        return OrderFormImageTableDef.orderFormImage;
    }


    @Override
    public List<OrderFormImage> getByOrderCode(String orderCode) {
        return getMapper().selectListByCondition(table.orderCode.eq(orderCode));
    }

    @Override
    public List<OrderFormImage> getByOrderCodes(List<String> orderCode) {
        return getMapper().selectListByCondition(table.orderCode.in(orderCode));
    }

    @Override
    public int dropByOrderCodeAndId(String code, Long imgId) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.orderCode.eq(code))
                .and(table.id.eq(imgId));
        return getMapper().deleteByCondition(condition);
    }

    @Override
    public long getImgNum(String code) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.orderCode.eq(code));
        return getMapper().selectCountByCondition(condition);
    }
}
